//
//  SEGActivitySignAlertView.m
//  SEGUhomeSommunitySocial
//
//  Created by 乔杨 on 2019/4/12.
//  Copyright © 2019 刘山. All rights reserved.
//

#import "SEGActivitySignAlertView.h"

@interface SEGActivitySignAlertView ()

/** 背景图 */
@property (nonatomic, strong) UIView *bgView;
/** 标题Lab */
@property (nonatomic, strong) UILabel *titleLab;
/** 图片 */
@property (nonatomic, strong) UIImageView *imageView;
/** 值Lab */
@property (nonatomic, strong) UILabel *valueLab;
/** 描述Lab */
@property (nonatomic, strong) UILabel *desLab;
/** line */
@property (nonatomic, strong) UIView *line;
/** 知道了按钮 */
@property (nonatomic, strong) UIButton *knowBtn;

@end

@implementation SEGActivitySignAlertView

- (instancetype)init {
    if (self = [super init]) {
        self.frame = CGRectMake(0, 0, kScreenWidth, LYScreenHeight());

        [self createUI];
    }
    return self;
}

#pragma mark - UI
- (void)createUI {
    [self addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).mas_offset(50);
        make.right.equalTo(self).mas_offset(-50);
        make.centerY.equalTo(self.mas_centerY);
        make.height.mas_equalTo(260);
    }];
    
    [self.bgView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).mas_offset(10);
        make.left.right.equalTo(self.bgView);
        make.height.mas_equalTo(40);
    }];
    
    UIImage *image = [UIImage imageWithContentsOfFile:SEGPicName(@"pic_checkin_success")];
    self.imageView.image = image;
    [self.bgView addSubview:self.imageView];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLab.mas_bottom);
        make.centerX.equalTo(self.bgView.mas_centerX);
        make.height.mas_equalTo(image.size.height);
        make.width.mas_equalTo(image.size.width);
    }];
    
    [self.bgView addSubview:self.valueLab];
    [self.valueLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageView.mas_bottom).mas_offset(8);
        make.centerX.equalTo(self.bgView.mas_centerX);
        make.height.mas_equalTo(17+14);
    }];
    
    [self.bgView addSubview:self.desLab];
    [self.desLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.valueLab.mas_bottom);
        make.centerX.equalTo(self.bgView.mas_centerX);
        make.height.mas_equalTo(14);
    }];

    [self.bgView addSubview:self.knowBtn];
    [self.knowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView.mas_bottom).mas_offset(-44);
        make.left.equalTo(self.bgView);
        make.width.equalTo(self.bgView);
        make.height.mas_equalTo(44);
    }];
    
    [self.bgView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView);
        make.bottom.equalTo(self.knowBtn.mas_top);
        make.width.equalTo(self.bgView);
        make.height.mas_equalTo(0.5);
    }];
}
- (void)signAlertView_refreshAlertViewWithType:(SignAwardType)type value:(NSInteger)value {
    if (type == SIGNTYPE_integral) {
        self.valueLab.text = [NSString stringWithFormat:@"获得%lu积分", (unsigned long)value];
    } else {
        self.valueLab.text = [NSString stringWithFormat:@"获得%lu成长值", (unsigned long)value];
    }
}

#pragma mark - Event
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self dismiss];
}
- (void)closeButtonClick {
    [self dismiss];
}

#pragma mark - Animation
- (void)show {
    self.hidden = NO;
    [UIView animateWithDuration:0.2f animations:^{
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7f];
        self.bgView.alpha = 1;
    }];
}
- (void)dismiss {
    [UIView animateWithDuration:0.2f animations:^{
        self.backgroundColor = [UIColor clearColor];
        self.bgView.alpha = 0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}

#pragma mark - Getter
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = kColor_W2;
        _bgView.layer.cornerRadius = 5;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = [UIFont boldSystemFontOfSize:19];
        _titleLab.textColor = kColor_1;
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.backgroundColor = kColor_W2;
        _titleLab.text = @"签到成功";
    }
    return _titleLab;
}
- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
    }
    return _imageView;
}
- (UILabel *)valueLab {
    if (!_valueLab) {
        _valueLab = [[UILabel alloc] init];
        _valueLab.font = [UIFont boldSystemFontOfSize:16];
        _valueLab.textColor = kColor_T;
        _valueLab.textAlignment = NSTextAlignmentCenter;
        _valueLab.backgroundColor = kColor_W2;
    }
    return _valueLab;
}
- (UILabel *)desLab {
    if (!_desLab) {
        _desLab = [[UILabel alloc] init];
        _desLab.font = kFont_13;
        _desLab.textColor = kColor_3;
        _desLab.textAlignment = NSTextAlignmentCenter;
        _desLab.backgroundColor = kColor_W2;
        _desLab.text = @"连续签到，积分翻倍哦！";
    }
    return _desLab;
}
- (UIView *)line {
    if (!_line) {
        _line = [UIView new];
        _line.backgroundColor = kColor_L4;
    }
    return _line;
}
- (UIButton *)knowBtn {
    if (!_knowBtn) {
        _knowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _knowBtn.backgroundColor = kColor_W2;
        [_knowBtn setTitleColor:kColor_1
                       forState:UIControlStateNormal];
        [_knowBtn setTitle:@"我知道了" forState:UIControlStateNormal];
        _knowBtn.titleLabel.font = kFont_16;
        [_knowBtn addTarget:self
                     action:@selector(closeButtonClick)
           forControlEvents:UIControlEventTouchUpInside];
    }
    return _knowBtn;
}

@end
